<html>
<head><meta charset="utf-8"><title>Building rustc_ast? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html">Building rustc_ast?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225825436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225825436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225825436">(Feb 10 2021 at 11:57)</a>:</h4>
<p>If I install a nightly (I think with the rustc_dev component) I can build crates that use rustc_ast, but I can't build those crates with my stage 1 builds as apparently rustc_ast is either not built or not available for importing. I checked config.toml but couldn't see any relevant fields. How do I build it + make it available for importing?</p>



<a name="225837299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225837299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225837299">(Feb 10 2021 at 13:46)</a>:</h4>
<p><span class="user-mention" data-user-id="119169">@osa1</span> so this is weird - you actually need to build the compiler <em>twice</em>: <code>x.py build --stage 1 compiler/rustc</code>. The reason for that is the stage1 compiler was generated by stage0, but programs using rustc_private will be compiled by stage1, which has a different ABI.</p>



<a name="225837380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225837380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225837380">(Feb 10 2021 at 13:47)</a>:</h4>
<p>It doesn't come up for distributed artifacts because the stage2 compiler was built from the same source as stage1, so it has the same ABI</p>



<a name="225837709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225837709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225837709">(Feb 10 2021 at 13:49)</a>:</h4>
<p>Hmm so because rustc_private stuff are built with stage 1, which is built using stage 0 and has different ABI, stage 1 can't access rustc_private stuff, I need stage 2 for that? (where both the compiler itself and libraries will be built by the same compiler?)</p>
<p>Did I get this right?</p>



<a name="225837958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225837958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225837958">(Feb 10 2021 at 13:51)</a>:</h4>
<p>The property you need isn't "built by the same compiler", it's "built with the same ABI". So using a stage1 toolchain should be ok as long as you compile rustc twice with <code>build compiler/rustc</code>.</p>



<a name="225838086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225838086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225838086">(Feb 10 2021 at 13:52)</a>:</h4>
<p>The difference is that stage1/rustc and stage2/rustc may be different binaries (e.g. optimized differently) but they will still <em>produce</em> (compile) binaries with the same ABI</p>



<a name="225838195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225838195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225838195">(Feb 10 2021 at 13:53)</a>:</h4>
<p>OK, I think I got it. Thanks.</p>



<a name="225838400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Building%20rustc_ast%3F/near/225838400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Building.20rustc_ast.3F.html#225838400">(Feb 10 2021 at 13:55)</a>:</h4>
<p>Another way to think of it is that rustc_private is sort of the C equivalent of <code>rustc -lrustc</code>: you're linking the program to the same dynamic libraries the compiler uses</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>